package com.gao.pubsub.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

/**
 * 实现 MessageListener
 */
@Component
public class ReceiverRedisOnMessage implements MessageListener {
    Logger logger = LoggerFactory.getLogger(ReceiverRedisOnMessage.class);

    /**
     * 可以获取到消息和频道
     * @param message
     * @param pattern
     */
    @Override
    public void onMessage(Message message, byte[] pattern) {
        logger.info("onMessage：" + new String(message.getBody()));
        logger.info("onMessage：" + new String(message.getChannel()));
    }
}
